package com.guashu.springbootasynchronous.async.asyncAnnotation;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.CompletableFuture;

@RestController
public class AsyncController {

    @Resource
    AsyncService asyncService;


    @GetMapping("/runAsync1")
    public CompletableFuture<String> runAsyncMethod1() throws InterruptedException {
        asyncService.asyncMethodWithConfiguredExecutor();
        return CompletableFuture.completedFuture("直接返回结果");
    }

    @GetMapping("/runAsync2")
    public CompletableFuture<String> runAsyncMethod2() {
        asyncService.anotherAsyncMethod();
        return CompletableFuture.completedFuture("Task 2 executed asynchronously");
    }
}

